# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
from flask import Flask, request, jsonify
import os

app = Flask(__name__)

# 设置上传文件的保存目录
app.config['UPLOAD_FOLDER'] = 'uploads'
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)

@app.route('/', methods=['POST'])
def upload_file():
    # 检查请求中是否包含文件
    if 'file' not in request.files:
        return jsonify({'error': 'No file provided'})

    file = request.files['file']

    print(request.headers)

    # 检查文件是否为空
    if file.filename == '':
        return jsonify({'error': 'No file selected'})

    # 保存文件
    if file:
        path_name=os.path.join(app.config['UPLOAD_FOLDER'], file.filename) #图片路径
        file.save(path_name)
        #处理识别图片

        #删除图片返回结果
        # os.remove(path_name)

        return jsonify({'code':200,'type':'可回收垃圾','erros':'successful'})

if __name__ == '__main__':
    app.run(debug=True)



